//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<EntityManager.h>
///	@path	~/src/scene/
///	@date	2007/11/05
///	@desc	Manages entities' loading, placing, leaving & releasing.

#pragma once

#include "xeres.h"

#include <map>
#include <vector>

#include "lib/utilities/callback.h"

#include "scene/IEntity.h"

namespace xeres {

	/*!
		\class	EntityManager
		\brief	Manages entities' loading, placing, leaving & releasing.
				Used by scene manager.
	*/
	class EntityManager
	{
	protected:

		/// \name Constructor & Destructor
		//@{

		/// \ctor
		EntityManager( void );

		/// \dtor
		~EntityManager( void );

		//@}

		/// \name Internal Manipulation
		//@{

		/*!
			\brief		Initialize entity manager.
		*/
		void Initialize( void );

		/*!
			\brief		Finalize entity manager.
		*/
		void Finalize( void );

		//@}

	public:

		/// \name Interface Manipulation
		//@{

		/// \brief Tick update for every frame entity routine, not including entity's tick call.
		void Tick( const Frame& frame );

		/*!
			\brief		Creates an entity, and schedule resources for it.
						After resources are ready, entity will be initialized.
		*/
		bool CreateEntity(
			const WString& entityClass ,
			EntityID id ,
			std::vector< const WString& >& res ,
			function<void(RefWeak<IEntity>)> completeCallback
			);

		/*!
			\brief		Get entity from EntityID
		*/
		RefPass< IEntity > EntityFromID( EntityID id );

		//@}

	private:
		
		// data

		// entities
		typedef std::map< EntityID , Ref< IEntity > > EntityMap;
		EntityMap		m_entities;

	};

} // namespace xeres
